home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / elleu (IT).ifs < prev    next >
Encoding:
Text File  |  2004-10-12  |  8.1 KB  |  283 lines

  1. // GETINFO SCRIPTING
  2. // elleu (IT) by SM
  3.  
  4. (**************************************************
  5. *  Movie importation script for:                  *
  6. *      elleu - http://www.elleu.com               *
  7. *  Ver. 1.0.0 - 06.10.2004                        *
  8. *  Stefano Mora - stefano.mora@libero.it          *
  9. *                                                 *
  10. *  For use with Ant Movie Catalog 3.4.2           *
  11. *  www.ant.be.tf/moviecatalog ╖╖╖ www.buypin.com  *
  12. *                                                 *
  13. *  The source code of the script can be used in   *
  14. *  another program only if full credits to        *
  15. *  script author and a link to Ant Movie Catalog  *
  16. *  website are given in the About box or in       *
  17. *  the documentation of the program               *
  18. ***************************************************)
  19.  
  20. program elleu;
  21.  
  22. var
  23.  MovieName: string;
  24.  
  25. const
  26.   PATHLOG = 'c:\Programmi\Ant Movie Catalog\Log\LogElleu\';
  27.   SITE = 'http://www.elleu.com';
  28.   FILMURL = SITE+'/customer/';
  29.   MOVIE = 'Il commissario Montalbano - La gita a Tindari (Dvd)';
  30.  
  31. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  32. var
  33.   i: Integer;
  34. begin
  35.   result := -1;
  36.   if StartAt < 0 then
  37.     StartAt := 0;
  38.   for i := StartAt to List.Count-1 do
  39.     if Pos(Pattern, List.GetString(i)) <> 0 then
  40.     begin
  41.       result := i;
  42.       Break;
  43.     end;
  44. end;
  45.  
  46. // --------------------------------------------------
  47.  
  48. // Analizza la pagina e ricava i dati
  49. procedure LeggeFilm(Page: TStringList);
  50. var
  51.   strTmp, strTmp2, strTmp3: string;
  52.   LineNr: integer;
  53.   EndLine: integer;
  54.   BeginPos, EndPos: Integer;
  55.   bNome: boolean;
  56.   
  57. begin
  58.  
  59. // Titoli
  60.   LineNr := FindLine('Titolo', Page, 0);
  61.   strTmp := Page.GetString(LineNr);
  62.   // I dati sono tutti in questa riga !
  63.  
  64. // Immagine - fascetta
  65.   BeginPos := pos('fascette', strTmp)-15;
  66.   delete( strTmp, 1, BeginPos);
  67.   BeginPos := 0;
  68.   EndPos := pos('width', strTmp)-2;
  69.   strTmp2 := SITE+copy( strTmp, BeginPos, EndPos-BeginPos);
  70.   GetPicture(strTmp2, FALSE);
  71.   //ShowMessage(strTmp2);
  72.  
  73. // Titolo
  74.   BeginPos := pos('Titolo', strTmp);
  75.   delete( strTmp, 1, BeginPos+13);
  76.   //ShowMessage(strTmp);
  77.   BeginPos := 0;
  78.   EndPos := pos('<br>', strTmp)-1;
  79.   strTmp2 := trim(copy(strTmp, BeginPos, EndPos));
  80.   // Toglie il (dvd) o (vhs)
  81.   BeginPos := pos('(Dvd)', strTmp2);
  82.   if BeginPos <> 0 then strTmp2 := trim(copy (strTmp2, 1, BeginPos-1));
  83.   BeginPos := pos('(Vhs)', strTmp2);
  84.   if BeginPos <> 0 then strTmp2 := trim(copy (strTmp2, 1, BeginPos-1));
  85.   // Titolo originale === titolo tradotto
  86.   SetField( fieldTranslatedTitle, strTmp2);
  87.   SetField( fieldOriginalTitle, strTmp2);
  88.   //ShowMessage(strTmp2);
  89.  
  90. // Attori
  91.   BeginPos := pos('Attori:', strTmp);
  92.   delete( strTmp, 1, BeginPos+13);
  93.   BeginPos := 0;
  94.   EndPos := pos('<br>', strTmp)-1;
  95.   strTmp2 := copy(strTmp, BeginPos, EndPos);
  96.   SetField( fieldActors, strTmp2);
  97.   //ShowMessage(strTmp2);
  98.  
  99. // Regia
  100.   BeginPos := pos('Regia:', strTmp);
  101.   delete( strTmp, 1, BeginPos+13);
  102.   BeginPos := 0;
  103.   EndPos := pos('<br>', strTmp)-1;
  104.   strTmp2 := trim(copy(strTmp, BeginPos, EndPos));
  105.   SetField( fieldDirector, strTmp2);
  106.  
  107. // Genere
  108.   BeginPos := pos('Genere:', strTmp);
  109.   delete( strTmp, 1, BeginPos+13);
  110.   BeginPos := 0;
  111.   EndPos := pos('<br>', strTmp)-1;
  112.   strTmp2 := copy(strTmp, BeginPos, EndPos);
  113.   SetField( fieldCategory, trim(strTmp2));
  114.  
  115. // Durata
  116.   BeginPos := pos('Durata:', strTmp);
  117.   delete( strTmp, 1, BeginPos+13);
  118.   BeginPos := 0;
  119.   EndPos := pos('min', strTmp)-1;
  120.   strTmp2 := trim(copy(strTmp, BeginPos, EndPos));
  121.   SetField( fieldLength, trim(strTmp2));
  122.  
  123. // Anno
  124.   BeginPos := pos('Anno di p', strTmp);
  125.   if BeginPos = 0 then  // Non trovato -> linea successiva !
  126.     begin
  127.     strTmp := Page.GetString(LineNr+1);
  128.     BeginPos := pos('Anno di p', strTmp);
  129.     end
  130.   delete( strTmp, 1, BeginPos+34);
  131.   BeginPos := 0;
  132.   EndPos := pos('<br>', strTmp)-1;
  133.   strTmp2 := trim(copy(strTmp, BeginPos, EndPos));
  134.   SetField( fieldYear, strTmp2);
  135.  
  136. // Descrizione
  137.   BeginPos := pos('>Trama<', strTmp);
  138.   delete (strTmp, 1, BeginPos);
  139.  
  140.   BeginPos := pos('class="testo"', strTmp)+30;
  141.   delete (strTmp, 1, BeginPos);
  142.  
  143.   BeginPos := 0;
  144.   EndPos := pos('</td>', strTmp)-1;
  145.  
  146.   strTmp2 := copy( strtmp, BeginPos, EndPos-BeginPos);
  147.   HTMLRemoveTags(strTmp2);
  148.   SetField( fieldDescription, strTmp2);
  149.  
  150.   // Si sposta nella pagina dei risultati
  151.   DisplayResults;
  152. end;
  153.  
  154. // ---
  155.  
  156. procedure AnalyzePage(Address: string);
  157.  
  158. var
  159.   Page: TStringList;
  160.   strPage, MovieAddr, MovieTitle : string;
  161.   BeginPos, EndPos: Integer;
  162.   
  163.   LineNr: Integer;
  164.   rigalista: string;
  165.   rigahtml: string;
  166.   strTmp: string;
  167.   altrapagina: string;
  168.  
  169. begin
  170.   // Crea la lista
  171.   Page:= TStringList.Create;
  172.   
  173.   // Riceve la pagina
  174.   Page.Text := GetPage(Address);
  175.   //Page.SaveToFile(PATHLOG+MovieName+'.res');
  176.   //Page.LoadFromFile(PATHLOG+MOVIE+'.res');
  177.  
  178.   BeginPos:= FindLine('Nessun film trovato', Page, 0);
  179.   if BeginPos <> -1 then
  180.     begin
  181.     ShowMessage('Film non trovato !');
  182.     exit;
  183.     end;
  184.  
  185.   // Controllare che ci siano film !!
  186.   LineNr := FindLine('Prodotti trovati', Page, 0);
  187.   if(LineNr = -1) then
  188.     begin
  189.     // Trovato il film
  190.     // LeggeFilm(Page);
  191.     ShowMessage('Nessuna voce trovata');
  192.     end
  193.  
  194.   else  // Lista di film
  195.  
  196.     begin
  197.  
  198.     PickTreeClear;
  199.     PickTreeAdd('Risultati ricerca per "' + MovieName + '":', '');
  200.  
  201.     LineNr := FindLine('>Titolo<', Page, LineNr);
  202.     while LineNr <> -1 do
  203.       begin
  204.  
  205. // Titolo
  206.       rigahtml:= Page.GetString(LineNr);
  207.  
  208.       // Url
  209.       BeginPos:= pos('href=', rigahtml);
  210.       Delete(rigahtml, 1, BeginPos);
  211.  
  212.       BeginPos := 5;
  213.       EndPos:= pos(' class="te', rigahtml);
  214.       MovieAddr:= FILMURL+copy( rigahtml, BeginPos, EndPos-BeginPos);
  215.  
  216.       BeginPos:= pos('">', rigahtml)+2;
  217.       EndPos:= pos('</a>', rigahtml);
  218.       MovieTitle:= copy( rigahtml, BeginPos, EndPos-BeginPos);
  219.  
  220.       // Legge il regista
  221.       LineNr := FindLine('Regista:', Page, LineNr);
  222.       if LineNr <> -1 then
  223.         begin
  224.         strTmp := Page.GetString(LineNr);
  225.         BeginPos := pos('</span>', strTmp)+7;
  226.         EndPos := 1000;
  227.         strTmp := trim(copy(strTmp, BeginPos, EndPos-BeginPos));
  228.         MovieTitle := MovieTitle + ' - ' + strTmp;
  229.         end
  230.  
  231.       // Add to listbox
  232.       PickTreeAdd(MovieTitle, MovieAddr);
  233.  
  234.       // Restart the process
  235.       LineNr := LineNr+2;
  236.       LineNr := FindLine('>Titolo<', Page, LineNr);
  237.       end;
  238.  
  239.       // Controlla se ci sono altre pagine di risultati
  240.       LineNr := FindLine('>Avanti<', Page, LineNr);
  241.       if LineNr <> -1 then
  242.         begin
  243.         PickTreeAdd('Ci sono altre pagine risultato ...', '');
  244.         
  245.         // Estrae l'indirizzo per un'altra pagina
  246.         strTmp := Page.GetString(LineNr);
  247.         BeginPos := pos('href="', strTmp)+6;
  248.         EndPos := pos('" id=', strTmp);
  249.         altrapagina := copy( strTmp, BeginPos, EndPos-BeginPos);
  250.         //ShowMessage(altrapagina);
  251.         end;
  252.  
  253.       // Visualizza la lista e fa scegliere
  254.       if(PickTreeExec(Address)) then
  255.         begin
  256.         Page.text := GetPage(Address);
  257.         // Salva la pagina per debug
  258.             //Page.SaveToFile(PATHLOG+MovieName+'.film');
  259.             //Page.LoadFromFile(PATHLOG+MOVIE+'.film');
  260.         LeggeFilm(Page);
  261.         end;
  262.     end;
  263.   Page.Free();
  264. end;
  265.  
  266. // -------------------- main
  267.  
  268. begin
  269.   if CheckVersion(3,4,2) then
  270.   begin
  271.     // Considera il titolo tradotto, se vuoto il titolo originale
  272.     MovieName := GetField(fieldTranslatedTitle);
  273.     if MovieName = '' then MovieName := GetField(fieldOriginalTitle);
  274.     // Chiede conferma del titolo
  275.     Input('elleu Import', 'Titolo del film:', MovieName);
  276.     if MovieName <> '' then
  277.     begin
  278.       AnalyzePage('http://www.elleu.com/customer/search.php?substring='+UrlEncode(MovieName)+'&vers=DVD&showhow=simple&catebig%5B%5D=DVD&catebig%5B%5D=VHS&catebig%5B%5D=LIBRI&catebig%5B%5D=CD&ordersearch=add_date&typesearch=minisearch');
  279.     end;
  280.   end else
  281.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.2)');
  282. end.
  283.